package m.jclecai.com.view;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import m.jclecai.com.R;
import m.jclecai.com.inter.OnCautionDialogConfirmListener;

public class CautionDialog extends Dialog implements android.view.View.OnClickListener {

    private String content;
    private OnCautionDialogConfirmListener listener;

    /**
     * @param context
     * @param content
     * @param listener 提示dialog
     */
    public CautionDialog(Context context, String content, OnCautionDialogConfirmListener listener) {
        super(context, R.style.ProgressStyle);
        this.content = content;
        this.listener = listener;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.caution_dialog);
        init();
    }

    private void init() {

        //不允许后退键取消
        CautionDialog.this.setCancelable(false);
        TextView tv_content = (TextView) findViewById(R.id.tv_content);
        tv_content.setText(content);

        TextView tv_cancel = (TextView) findViewById(R.id.tv_cance);
        tv_cancel.setOnClickListener(this);

        TextView tv_confirm = (TextView) findViewById(R.id.tv_confirm);
        tv_confirm.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_confirm:
                listener.onConfirmListener();
                CautionDialog.this.dismiss();
                break;
            case R.id.tv_cance:
                listener.onCancelListener();
                CautionDialog.this.dismiss();
                break;
            default:
                break;
        }
    }
}
